const { AsyncParallelHook } = require("tapable");

class HYCompiler {
  constructor() {
    this.hooks = {
      // parallel: 并行，不会等到上一个事件回调执行结束，才执行下一次事件处理回调
      asyncParallelHook: new AsyncParallelHook(["name", "age"]),
    };

    this.hooks.asyncParallelHook.tapAsync("event1", (name, age) => {
      setTimeout(() => {
        console.log("event1事件执行了", name, age);
      }, 2000);
    });

    this.hooks.asyncParallelHook.tapAsync("event2", (name, age) => {
      setTimeout(() => {
        console.log("event1事件执行了", name, age);
      }, 2000);
    });
  }
}

setTimeout(() => {
  const compiler = new HYCompiler();
  compiler.hooks.asyncParallelHook.callAsync("why", 23);
}, 0);
